﻿//-----------------------------------------------------------------------------------------------------------
// WBFSSync Project by Omega Frost 
// http://wbfssync.codeplex.com/
//
// WBFSSync is Licensed under the terms of the 
// Microsoft Reciprocal License (Ms-RL)
//-----------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Shell;

namespace WbfsSync.Dialogs
{
    //-------------------------------------------------------------------------------------------------------
    // Interaction logic for DialogCopyFiles.xaml
    //-------------------------------------------------------------------------------------------------------
    public partial class DialogCopyFiles : Window
    {
        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public delegate void SetProgressDelegate(double max, double value);
        public void BeginSetProgress(double maximum, double value)
        {
            this.Dispatcher.BeginInvoke((SetProgressDelegate)delegate
                (double max, double val)
            {
                if (val >= 0)
                {
                    this.MainProgress.Foreground = new SolidColorBrush() 
                    { Color = new Color() { A = 255, R = 1, G = 211, B = 28 } };

                    this.MainProgress.IsIndeterminate = (val == 0);
                    this.MainProgress.Maximum = max;
                    this.MainProgress.Value = val;

                    if (this.TaskbarItemInfo != null)
                    {
                        this.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
                        this.TaskbarItemInfo.ProgressValue = val / max;
                    }
                }
                else if (val == -1) this.MainProgress.Foreground = Brushes.Yellow;
                else if (val == -2) this.MainProgress.Foreground = Brushes.Red;

            }, maximum, value);
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public delegate void SetBasicInfoDelegate(String name, String fromname, String fromdir, String toname, String todir);
        public void BeginSetBasicInfo(String name, String fromname, String fromdir, String toname, String todir)
        {
            this.Dispatcher.BeginInvoke((SetBasicInfoDelegate)delegate
                (String n, String fn, String fd, String tn, String td)
            {
                this.Title = name;
                this.InfoOperation.Text = name;

                this.InfoFromName.Text = fn;
                this.InfoFromDir.Text = fd;
                this.InfoToName.Text = tn;
                this.InfoToDir.Text = td;
            }, name, fromname, fromdir, toname, todir);
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public delegate void BeginShowDelegate();
        public void BeginShow()
        {
            this.Dispatcher.BeginInvoke((BeginShowDelegate)
                delegate() { this.Show(); });
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public delegate void BeginCloseDelegate();
        public void BeginClose()
        {
            this.Dispatcher.BeginInvoke((BeginCloseDelegate)
                delegate() { this.Close(); });
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public DialogCopyFiles()
        {
            InitializeComponent();

            try { this.TaskbarItemInfo = new TaskbarItemInfo(); }
            catch { }
        }
    }
}
